package com.enerccio.commonJ.tools;

import com.enerccio.commonJ.utils.Setfable;

/**
 * This class represents simple mutable pair that is never used in the commonJ public inteface, 
 * unlike the ConsCell.
 * @author enerccio
 *
 * @param <T>
 * @param <V>
 */
public class MutablePair<T, V> {
	
	private T t;
	private V v;
	
	/**
	 * Creates null mutable pair
	 */
	public MutablePair(){
		this(null, null);
	}
	
	/**
	 * Creates new mutable pair with t and v initially set
	 * @param t
	 * @param v
	 */
	public MutablePair(T t, V v){
		this.t = t;
		this.v = v;
	}

	/**
	 * Returns first object in the pair
	 * @return
	 */
	@Setfable
	public T getFirst(){
		return t;
	}
	
	/**
	 * Sets the first object in the pair
	 * @param t
	 */
	public void setfGetFirst(T t){
		this.t = t;
	}
	
	/**
	 * Returns second object in the pair
	 * @return
	 */
	@Setfable
	public V getSecond(){
		return v;
	}
	
	/**
	 * Sets the second object in the pair
	 * @param v
	 */
	public void setfGetSecond(V v){
		this.v = v;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object o){
		if (o instanceof MutablePair<?, ?>)
			if (((MutablePair<T, V>) o).v.equals(v) && ((MutablePair<T, V>) o).t.equals(t))
				return true;
		return false;
	}
	
	@Override
	public String toString(){
		return "("+t.toString()+", "+v.toString()+")";
	}
}
